n = int(input())
c = 0
m = 0
x = n // 1000
if n > 999 and n < 10000:
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
    if c <= 2:
        m = max(x, m)
    else:
        m = m
    x = n // 100
    c = 0
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
        
    if c <= 2:
        m = max(x, m)
    else:
        m = m
    x = n // 10
    c = 0
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
        
    if c <= 2:
        m = max(x, m)
    else:
        m = m
    c = 0 
    for i in range(1, n + 1):
        if n % i == 0:
            c += 1
        
    if c <= 2:
        m = max(n, m)
    else:
        m = m

    x = n
    x = str(n)
    x = x[1]
    x = int(x)
    c = 0 
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
        
    if c <= 2:
        m = max(x, m)
    else:
        m = m
    x = n
    x = str(n)
    x = x[1:3]
    x = int(x)
    c = 0 
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
        
    if c <= 2:
        m = max(x, m)
    else:
        m = m
    x = n
    x = str(n)
    x = x[1:4]
    x = int(x)
    c = 0 
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
        
    if c <= 2:
        m = max(x, m)
    else:
        m = m
    x = n
    x = str(n)
    x = x[2]
    x = int(x)
    c = 0
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
    if c <= 2:
        m = max(x,m)
    else:
        m = m
    x = n
    x = str(n)
    x = x[2:4]
    x = int(x)
    c = 0
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
    if c <= 2:
        m = max(x,m)
    else:
        m = m
    x = n
    x = str(n)
    x = x[3]
    x = int(x)
    c = 0
    for i in range(1, x + 1):
        if x % i == 0:
            c += 1
    if c <= 2:
        m = max(x,m)
    else:
        m = m
    print(m)
else:
    print("0")


